package log

import "github.com/astaxie/beego/logs"

var Log *logs.BeeLogger

func init() {
	Log = logs.NewLogger(1000)
	Log.EnableFuncCallDepth(true)
	Log.SetLogFuncCallDepth(Log.GetLogFuncCallDepth() + 1)
}

func InitLog(logWay, logFile, logLevel string) {
	SetLogFile(logWay, logFile)
	SetLogLevel(logLevel)
}

func SetLogFile(logWay, logFile string) {
	switch logWay {
	case "console":
		logs.SetLogger("console")
	default:
		logs.SetLogger("file", `{"filename":"`+logFile+`"}`)
	}
}

func SetLogLevel(logLevel string) {
	level := 4 //warning

	switch logLevel {
	case "debug":
		level = 7
	case "info":
		level = 6
	case "warn":
		level = 4
	case "error":
		level = 3
	default:
		level = 4
	}

	Log.SetLevel(level)
}

// wrap log
func Error(format string, v ...interface{}) {
	Log.Error(format, v...)
}

func Warn(format string, v ...interface{}) {
	Log.Warn(format, v...)
}

func Info(format string, v ...interface{}) {
	Log.Info(format, v...)
}

func Debug(format string, v ...interface{}) {
	Log.Debug(format, v...)
}
